﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_GoodsDetails : IGoodsDetails
    {
        public void Add(GoodsDetails item)
        {
            CakeEntities db = new CakeEntities();
            db.GoodsDetails.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.GoodsDetails.Remove(db.GoodsDetails.Find(id));
            db.SaveChanges();
        }

        public GoodsDetails FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.GoodsDetails.Find(id);
        }

        public List<GoodsDetails> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.GoodsDetails.ToList();
        }

        public void Updata(int id, GoodsDetails item)
        {
            CakeEntities db = new CakeEntities();
            var data = db.GoodsDetails.Find(id);
            if (data != null)
            {
                data.GoodsId=item.GoodsId;
                data.Details=item.Details;
                db.SaveChanges();
            }
        }
    }
}
